<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../assets/js/vue.js"></script>
</head>
<body>
    <div id="app">
        <p>{{ users }}</p>
        <input type="text" v-model="users.name">
        <input type="button" value="撤销监听" onclick="watchUser()">
        <hr>
        <p>{{ users }}</p>
        <input type="text" v-model="users.name">
        <input type="button" value="加载监听" @click="addWatch()">
        <input type="button" value="撤销监听" @click="removeWatch()">
        <hr>
        <p>num1+num2= {{ num1+num2 }} </p>
        <!-- <p>num1+num2= {{ sum }} </p> -->
        <input type="number" v-model.number="num1">
        <input type="number" v-model.number="num2">
    </div>
    <script>
       var vm= new Vue({
            el:"#app",
            data:{
                  users:{
                      name:"rick",
                      age:18
                  },
                  num1:10,
                  num2:11, 
            },
            // computed:{
            //     sum(){
            //         return this.num1+this.num2;
            //     }
            // },
            methods: {
                addWatch(){
                    if(!this.$watchUser){
                        this.$watchUser=this.$watch("users",(nv,ov)=>{
                        console.log("user在vue中被调用",nv,ov)                       
                        },{deep:true})
                    }
                },
                removeWatch(){
                    this.$watchUser();
                    this.$watchUser=null;
                }

            },
        })
    //    var watchUser= vm.$watch("users",function(nv,ov){
    //         console.log("users被改变")
    //     },{deep:true})
        vm.$watch(function(){
            // return this.num1+this.num2;
            // return [this.num1,this.num2];
            return {num1:this.num1,num2:this.num2};

        },function(nv,ov){
            console.log("多参数调用",nv,ov);
        },{deep:true})
    </script>
</body>
</html>